package com.beiing.tianshuai.tianshuai.widget;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.StyleRes;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.beiing.tianshuai.tianshuai.R;

/**
 * Created by Jinni on 2017/9/29 0029.
 */

public class DownLoadProgressDialog extends AlertDialog {

    private ProgressBar mProgressBar;
    private TextView mTvPercent;
    private Button mBtnUpdateBackground;

    private String mPercent;
    private float mMax;
    private int mProgress;

    private Context mContext;

    private OnClickListener mListener;

    public void setListener(OnClickListener listener) {
        mListener = listener;
    }

    protected DownLoadProgressDialog(Context context) {
        super(context);
    }

    public DownLoadProgressDialog(Context context, @StyleRes int themeResId) {
        super(context, themeResId);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_download_progress);
        setCanceledOnTouchOutside(false);
        initView();
    }

    private void initView() {
        mTvPercent = (TextView) findViewById(R.id.tv_percent);
        mProgressBar = (ProgressBar) findViewById(R.id.pb_download_progress);
        mBtnUpdateBackground = (Button) findViewById(R.id.btn_update_background);

        mBtnUpdateBackground.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onBackGroundClickListener(v);
                }
            }
        });
    }

    public void setMax(float max) {
        mMax = max;
        if (mProgressBar != null) {
            mProgressBar.setMax((int) mMax);
        }
    }

    public void setProgress(int progress) {
        mProgress = progress;
        if (mProgressBar != null) {
            mProgressBar.setProgress(progress);
        }
    }

    public void setPercent(String percent) {
        mPercent = percent;
        if (mTvPercent != null) {
            mTvPercent.setText(mPercent);
        }
    }

    public interface OnClickListener{
        void onBackGroundClickListener(View view);
    }
}
